﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ZHDJ.Data.BLL;
using ZHDJ.Data.Models.Org;
using ZHDJ.WebPage;

namespace ZHDJ.Web.WS
{
    /// <summary>
    /// AddScore 的摘要说明
    /// </summary>
    public class AddScore : PortalPage, IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");
            string loginId = HttpContext.Current.Request.Form["loginId"];
            AddScores(loginId);
        }

        /// <summary>
        /// 添加积分
        /// </summary>
        public void AddScores(string loginId)
        {
            if (loginId == string.Empty)
                return;

            PartyOrgMember user = DB.PartyOrgMembers.Where(u => u.LoginID == loginId).FirstOrDefault();
            if (user == null)
                return;

            bool isFirstLogin = Convert.ToBoolean(user.IsFirstLogin);
            if (isFirstLogin)
            {
                //添加登录积分
                PartyScoreHelper.Add(() => PartyScoreHelper.AddDayLogin(loginId));
                //修改当前登录人的“第一次登录”= 0
                PartyOrgMember.UpdateIsFirstLogin(loginId, 0);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}